import {ref} from 'vue'

export default function delTodo(){

// 删除
  let dcount=ref(1);

  let del=(id:number)=>{
    let arr=JSON.parse(localStorage.todo)
    // 循环所有数据
     arr._value.forEach((item:any,index:number)=>{
      if(id==item.id){
        arr._value.splice(index,1)
      }
    })
    localStorage.todo=JSON.stringify(arr)
    dcount.value++
  }
  // 单选
  let itemChange=(id:number)=>{
    let arr=JSON.parse(localStorage.todo)
    arr._value.forEach((item:any,index:any)=>{
      if(item.id==id){
        arr._value[index].isDone=!arr._value[index].isDone;
      }
    })
    localStorage.todo=JSON.stringify(arr)
    dcount.value++
  }
  return {
    itemChange,
    del,
    dcount
  }

}